package com.gitee.zycra.future.job.common.vo;

import com.gitee.zycra.future.job.common.model.JobNode;
import lombok.Getter;
import lombok.Setter;
import lombok.ToString;
import lombok.experimental.Accessors;

/**
 * @author zycra
 */
@Getter
@Setter
@ToString
@Accessors(chain = true)
public class JobNodeVO {

    /**
     * 主键
     */
    private Long id;

    /**
     * 节点IP地址
     */
    private String nodeIp;

    /**
     * CPU使用率
     */
    private Integer cpuUsedRatio;

    /**
     * 内存使用率
     */
    private Integer memoryUsedRatio;

    /**
     * 正在执行的任务数量
     */
    private Integer runningCount;

    /**
     * 是否存活(0:否,1:是)
     */
    private Boolean alive;

    /**
     * 类型转换
     *
     * @param jobNode 节点对象
     * @return 节点视图对象
     */
    public static JobNodeVO convertToJobNodeVO(JobNode jobNode) {
        if (jobNode == null) {
            return null;
        }
        return new JobNodeVO()
                .setId(jobNode.getId())
                .setNodeIp(jobNode.getNodeIp())
                .setAlive(jobNode.getAlive())
                .setMemoryUsedRatio(jobNode.getMemoryUsedRatio())
                .setCpuUsedRatio(jobNode.getCpuUsedRatio())
                .setRunningCount(jobNode.getRunningCount());
    }
}
